package com.example.asyncio;

import com.example.base.FlinkStreamSource;
import com.example.entity.Customer;
import org.apache.flink.streaming.api.datastream.AsyncDataStream;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.concurrent.TimeUnit;

/**
 * Author wangJinLong
 * Date 2025/8/18 11:11
 **/
public class AsyncioStream {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
        environment.setParallelism(1);

        DataStream<Customer> customerSource = FlinkStreamSource.getCustomerSource(environment);

        SingleOutputStreamOperator<Customer> unordereded = AsyncDataStream.unorderedWait(
                customerSource,
                new AsyncDatabaseRequest(),
                3,
                TimeUnit.SECONDS,
                50
        );

        unordereded.print();

        environment.execute();

    }

}
